package com.dianning.web.action.jiaoyou;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.*;

import com.dianning.bean.Area;
import com.dianning.bean.ChannelContact;
import com.dianning.bean.Company;
import com.dianning.bean.Info;
import com.dianning.bean.InfoExpand;
import com.dianning.bean.Money;
import com.dianning.bean.Parameter;
import com.dianning.bean.Profile;
import com.dianning.bean.Resume;
import com.dianning.bean.TradingArea;
import com.dianning.bean.UserDetail;
import com.dianning.bean.UserInfo;
import com.dianning.bean.Visitor;
import com.dianning.comm.ChannelConfig;
import com.dianning.comm.Constant;
import com.dianning.comm.DianningUtil;
import com.dianning.comm.OrderObj;
import com.dianning.comm.Util;
import com.dianning.exception.DianningException;
import com.dianning.service.AreaService;
import com.dianning.service.ChannelService;
import com.dianning.service.InfoService;
import com.dianning.service.ParameterService;
import com.dianning.service.UserInfoService;
import com.dianning.service.VisitorService;
import com.dianning.service.web.PageList;
import com.dianning.service.web.Pages;
import com.dianning.web.action.BaseAction;
import com.dianning.web.interceptor.RemoteAddrAware;
import com.dianning.web.interceptor.UserSessionAware;
import com.dianning.web.servlet.UserSession;
import com.dianning.web.ui.OptionsLong;

public class Nanyou extends BaseAction implements UserSessionAware{

	private static final Log logger = LogFactory.getLog(Nanyou.class);
	
	private InfoService infoService;
	private ChannelService channelService;
	private ParameterService parameterService;
	private AreaService areaService;
	private UserInfoService userInfoService;


	public InfoService getInfoService() {
		return infoService;
	}

	public void setInfoService(InfoService infoService) {
		this.infoService = infoService;
	}
	
	public ChannelService getChannelService() {
		return channelService;
	}

	public void setChannelService(ChannelService channelService) {
		this.channelService = channelService;
	}

	public ParameterService getParameterService() {
		return parameterService;
	}

	public void setParameterService(ParameterService parameterService) {
		this.parameterService = parameterService;
	}

	public AreaService getAreaService() {
		return areaService;
	}

	public void setAreaService(AreaService areaService) {
		this.areaService = areaService;
	}

	public UserInfoService getUserInfoService() {
		return userInfoService;
	}

	public void setUserInfoService(UserInfoService userInfoService) {
		this.userInfoService = userInfoService;
	}
	
	private UserSession userSession;

	public UserSession getUserSession() {
		return userSession;
	}

	public void setUserSession(UserSession userSession) {
		this.userSession = userSession;
	}
	
	private List jiaoyouNanyouTypeList = new ArrayList();
	private List xingbieList = new ArrayList();
	private List ageList = new ArrayList();
	private List fangcheList = new ArrayList();
	private List shouruList = new ArrayList();
	private List xuexingList = new ArrayList();
	private List xingzuoList = new ArrayList();
	private List hunyinList = new ArrayList();
	private List shengaoList = new ArrayList();
	private List tizhongList = new ArrayList();
	private List xueliList = new ArrayList();
	private List zhiyeList = new ArrayList();

	public List getJiaoyouNanyouTypeList() {
		return jiaoyouNanyouTypeList;
	}

	public void setJiaoyouNanyouTypeList(List jiaoyouNanyouTypeList) {
		this.jiaoyouNanyouTypeList = jiaoyouNanyouTypeList;
	}

	public List getXingbieList() {
		return xingbieList;
	}

	public void setXingbieList(List xingbieList) {
		this.xingbieList = xingbieList;
	}

	public List getAgeList() {
		return ageList;
	}

	public void setAgeList(List ageList) {
		this.ageList = ageList;
	}

	public List getFangcheList() {
		return fangcheList;
	}

	public void setFangcheList(List fangcheList) {
		this.fangcheList = fangcheList;
	}

	public List getShouruList() {
		return shouruList;
	}

	public void setShouruList(List shouruList) {
		this.shouruList = shouruList;
	}

	public List getXuexingList() {
		return xuexingList;
	}

	public void setXuexingList(List xuexingList) {
		this.xuexingList = xuexingList;
	}

	public List getXingzuoList() {
		return xingzuoList;
	}

	public void setXingzuoList(List xingzuoList) {
		this.xingzuoList = xingzuoList;
	}

	public List getHunyinList() {
		return hunyinList;
	}

	public void setHunyinList(List hunyinList) {
		this.hunyinList = hunyinList;
	}

	public List getShengaoList() {
		return shengaoList;
	}

	public void setShengaoList(List shengaoList) {
		this.shengaoList = shengaoList;
	}

	public List getTizhongList() {
		return tizhongList;
	}

	public void setTizhongList(List tizhongList) {
		this.tizhongList = tizhongList;
	}

	public List getXueliList() {
		return xueliList;
	}

	public void setXueliList(List xueliList) {
		this.xueliList = xueliList;
	}

	public List getZhiyeList() {
		return zhiyeList;
	}

	public void setZhiyeList(List zhiyeList) {
		this.zhiyeList = zhiyeList;
	}

	private void setJiaoyouNanyouTypeListValues(){
		List l = this.getParameterService().findParameters("jiaoyouNanyouType", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			jiaoyouNanyouTypeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setXingbieListListValues(){
		List l = this.getParameterService().findParameters("jiaoyouXingbie", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			xingbieList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setAgeListValues(){
		List l = this.getParameterService().findParameters("jiaoyouAge", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			ageList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setFangcheListValues(){
		List l = this.getParameterService().findParameters("jiaoyouFangche", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			fangcheList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setShouruListValues(){
		List l = this.getParameterService().findParameters("jiaoyouShouru", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			shouruList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setXuexingListValues(){
		List l = this.getParameterService().findParameters("jiaoyouXuexing", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			xuexingList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setXingzuoListValues(){
		List l = this.getParameterService().findParameters("jiaoyouXingzuo", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			xingzuoList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setHunyinListValues(){
		List l = this.getParameterService().findParameters("jiaoyouHunyin", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			hunyinList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setShengaoListValues(){
		List l = this.getParameterService().findParameters("jiaoyouShengao", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			shengaoList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setTizhongListValues(){
		List l = this.getParameterService().findParameters("jiaoyouTizhong", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			tizhongList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setXueliListValues(){
		List l = this.getParameterService().findParameters("jiaoyouXueli", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			xueliList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}
	private void setZhiyeListValues(){
		List l = this.getParameterService().findParameters("jiaoyouZhiye", 2, null, "orders", 0);
		for(int i=0;i<l.size();i++){
			Parameter p = (Parameter) l.get(i);
			zhiyeList.add(new OptionsLong(p.getId(), p.getParamName()));
		}
	}

	
	private void initValues(){
		setJiaoyouNanyouTypeListValues();
		setXingbieListListValues();
		setAgeListValues();
		setFangcheListValues();
		setShouruListValues();
		setXuexingListValues();
		setXingzuoListValues();
		setHunyinListValues();
		setShengaoListValues();
		setTizhongListValues();
		setXueliListValues();
		setZhiyeListValues();
		this.setBigChannel(this.getChannelService().findChannelContactById(this.bid));
		this.setSmallChannel(this.getChannelService().findChannelContactById(this.sid));
		this.setArea(this.getAreaService().findAreaById(this.areaId));
		if(this.areaId == -1){
			this.areaId = 0;
		}
		if(this.tid == -1){
			this.tid = 0;
		}
		this.setTradingArea(this.getAreaService().findTradingAreaById(this.tid));
	}
	
	private long id;
	private long bid = ChannelConfig.JIAOYOU_ID;
	private long sid = ChannelConfig.JIAOYOU_NANYOU_ID;
	private long areaId = -1;
	private long allTop = 1;
	private long tid = -1;
	private String title = "";
	private int isbiz = -1;
	private boolean biz = false;
	private boolean profile = true;
	private String content;
	private List photo;
	private int photonum;
	private String linkman;
	private String phone;
	
	private long jiaoyouNanyouType = -1;
	private long xingbie = -1;
	private long nianling = 0;
	private long fangche = -1;
	private long shouru = -1;
	private long xuexing = -1;
	private long xingzuo = -1;
	private long hunyin = -1;
	private long shengao = -1;
	private long tizhong = -1;
	private long xueli = -1;
	private long zhiye = -1;
	private String aihao;
	private String qq;
	
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getBid() {
		return bid;
	}

	public void setBid(long bid) {
		this.bid = bid;
	}

	public long getSid() {
		return sid;
	}

	public void setSid(long sid) {
		this.sid = sid;
	}public long getAreaId() {
		return areaId;
	}

	public void setAreaId(long areaId) {
		this.areaId = areaId;
	}

	public long getAllTop() {
		return allTop;
	}

	public void setAllTop(long allTop) {
		this.allTop = allTop;
	}


	public long getTid() {
		return tid;
	}

	public void setTid(long tid) {
		this.tid = tid;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public long getJiaoyouNanyouType() {
		return jiaoyouNanyouType;
	}

	public void setJiaoyouNanyouType(long jiaoyouNanyouType) {
		this.jiaoyouNanyouType = jiaoyouNanyouType;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getLinkman() {
		return linkman;
	}

	public void setLinkman(String linkman) {
		this.linkman = linkman;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public int getIsbiz() {
		return isbiz;
	}

	public void setIsbiz(int isbiz) {
		this.isbiz = isbiz;
	}

	public boolean isBiz() {
		return biz;
	}

	public void setBiz(boolean biz) {
		this.biz = biz;
	}

	public boolean isProfile() {
		return profile;
	}

	public void setProfile(boolean profile) {
		this.profile = profile;
	}


	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public List getPhoto() {
		return photo;
	}

	public void setPhoto(List photo) {
		this.photo = photo;
	}

	public int getPhotonum() {
		return photonum;
	}

	public void setPhotonum(int photonum) {
		this.photonum = photonum;
	}

	public long getXingbie() {
		return xingbie;
	}

	public void setXingbie(long xingbie) {
		this.xingbie = xingbie;
	}

	public long getNianling() {
		return nianling;
	}

	public void setNianling(long nianling) {
		this.nianling = nianling;
	}

	public long getFangche() {
		return fangche;
	}

	public void setFangche(long fangche) {
		this.fangche = fangche;
	}

	public long getShouru() {
		return shouru;
	}

	public void setShouru(long shouru) {
		this.shouru = shouru;
	}

	public long getXuexing() {
		return xuexing;
	}

	public void setXuexing(long xuexing) {
		this.xuexing = xuexing;
	}

	public long getXingzuo() {
		return xingzuo;
	}

	public void setXingzuo(long xingzuo) {
		this.xingzuo = xingzuo;
	}

	public long getHunyin() {
		return hunyin;
	}

	public void setHunyin(long hunyin) {
		this.hunyin = hunyin;
	}

	public long getShengao() {
		return shengao;
	}

	public void setShengao(long shengao) {
		this.shengao = shengao;
	}

	public long getTizhong() {
		return tizhong;
	}

	public void setTizhong(long tizhong) {
		this.tizhong = tizhong;
	}

	public long getXueli() {
		return xueli;
	}

	public void setXueli(long xueli) {
		this.xueli = xueli;
	}

	public long getZhiye() {
		return zhiye;
	}

	public void setZhiye(long zhiye) {
		this.zhiye = zhiye;
	}

	public String getAihao() {
		return aihao;
	}

	public void setAihao(String aihao) {
		this.aihao = aihao;
	}
	
	private Info info;
	private List sameAreas;
	private List sameUsers;
	private PageList pageList;
	private List areas;
	private String domain = Constant.DOMAIN;
	private String profileDomain = Constant.PROFILE_DOMAIN;
	private ChannelContact bigChannel;
	private ChannelContact smallChannel;
	private Area area;
	private TradingArea tradingArea;
	private List jiaoyouNanyouTypes;
	private List jiaoyouAges;
	private long jiaoyouAge = -1;
	
	public Info getInfo() {
		return info;
	}

	public void setInfo(Info info) {
		this.info = info;
	}
	
	public List getSameAreas() {
		return sameAreas;
	}

	public void setSameAreas(List sameAreas) {
		this.sameAreas = sameAreas;
	}

	public List getSameUsers() {
		return sameUsers;
	}

	public void setSameUsers(List sameUsers) {
		this.sameUsers = sameUsers;
	}

	public PageList getPageList() {
		return pageList;
	}

	public void setPageList(PageList pageList) {
		this.pageList = pageList;
	}

	public List getAreas() {
		return areas;
	}

	public void setAreas(List areas) {
		this.areas = areas;
	}
	

	public String getDomain() {
		return domain;
	}

	public void setDomain(String domain) {
		this.domain = domain;
	}

	public String getProfileDomain() {
		return profileDomain;
	}

	public void setProfileDomain(String profileDomain) {
		this.profileDomain = profileDomain;
	}

	public ChannelContact getBigChannel() {
		return bigChannel;
	}

	public void setBigChannel(ChannelContact bigChannel) {
		this.bigChannel = bigChannel;
	}

	public ChannelContact getSmallChannel() {
		return smallChannel;
	}

	public void setSmallChannel(ChannelContact smallChannel) {
		this.smallChannel = smallChannel;
	}

	public Area getArea() {
		return area;
	}

	public void setArea(Area area) {
		this.area = area;
	}

	public TradingArea getTradingArea() {
		return tradingArea;
	}

	public void setTradingArea(TradingArea tradingArea) {
		this.tradingArea = tradingArea;
	}

	public List getJiaoyouNanyouTypes() {
		return jiaoyouNanyouTypes;
	}

	public void setJiaoyouNanyouTypes(List jiaoyouNanyouTypes) {
		this.jiaoyouNanyouTypes = jiaoyouNanyouTypes;
	}

	public List getJiaoyouAges() {
		return jiaoyouAges;
	}

	public void setJiaoyouAges(List jiaoyouAges) {
		this.jiaoyouAges = jiaoyouAges;
	}

	public long getJiaoyouAge() {
		return jiaoyouAge;
	}

	public void setJiaoyouAge(long jiaoyouAge) {
		this.jiaoyouAge = jiaoyouAge;
	}

	public String execute() {
		try {
			return this.executeMethod(this.getAction());
		} catch (Exception e) {
			logger.error(e);
			return ERROR;
		}
	}

	public String index(){
		this.setInfo(this.getInfoService().findInfoById(this.id));
		if(this.getInfo() == null){
			return "infodisable";
		}else{
			if(this.getInfo().getValidated() == 2){
				return "infodisable";
			}
		}
		this.setSameAreas(this.getInfoService().findInfos(id,-1, this.getInfo().getCcid(), 1, 1, -1, "addTime", 1, 1, 5));
		this.setSameUsers(this.getInfoService().findInfos(id,this.getInfo().getUid(), this.getInfo().getCcid(), 1, 1, -1, "addTime", 1, 1, 5));
        return "index";
	}
	
	public String list(){
		if(this.areaId == 0){
			this.areaId = -1;
		}
		if(this.tid == 0){
			this.tid = -1;
		}
		this.setAreas(this.getAreaService().findAreas("orders", 0));
		this.setJiaoyouNanyouTypes(this.getParameterService().findParameters("jiaoyouNanyouType", 2, null, "orders", 0));
		this.setJiaoyouAges(this.getParameterService().findParameters("jiaoyouAge", 2, null, "orders", 0));
		Pages pages = new Pages();
		pages.setPage(this.getPage());
		pages.setPerPageNum(Constant.PAGE_NUM);
		if (this.getTotal() > 0) {
			pages.setTotalNum(this.getTotal());
		}
		pages.setFileName("/jiaoyou/nanyou.action?action=list&areaId="+this.areaId+"&tid="+this.tid+"&isbiz="+this.isbiz+"&jiaoyouAge="+this.jiaoyouAge+"&jiaoyouNanyouType="+this.jiaoyouNanyouType+"&title="+this.title);
		List wherein = new ArrayList();
		if(jiaoyouAge != -1){
			wherein.add("keyword='jiaoyouAge' and ivalue=" + jiaoyouAge);
		}
		if(jiaoyouNanyouType != -1){
			wherein.add("keyword='jiaoyouNanyouType' and ivalue=" + jiaoyouNanyouType);
		}
		OrderObj commend = new OrderObj();
		commend.setOrderBy("isCommend");
		commend.setAscOrDesc(1);
		OrderObj top = new OrderObj();
		if(this.areaId == -1){
			top.setOrderBy("isCityTop");
			top.setAscOrDesc(1);
		}else{
			this.allTop = -1;
			top.setOrderBy("isAreaTop");
			top.setAscOrDesc(1);
		}
		OrderObj up = new OrderObj();
		up.setOrderBy("upTime");
		up.setAscOrDesc(1);
		OrderObj[] oo = {commend,top,up};
		this.setPageList(this.getInfoService().findInfos(-1, -1, sid, areaId, tid, isbiz, 1, 1,-1,title, wherein, oo, pages));
		return "list";
	}
	public String post(){
		initValues();
		this.setAction("dopost");
		UserInfo ui = this.getUserInfoService().findUserInfoByUid(userSession.getUid());
		this.setLinkman(ui.getName());
		this.setPhone(ui.getUserDetail().getMobile());
		return "post";
	}
	
	public String dopost(){
		ChannelContact cc = this.getChannelService().findChannelContactById(this.sid);
		Info info = new Info();
		info.setCid(cc.getChannelId());
		info.setCcid(this.sid);
		info.setTitle(DianningUtil.filterKeyword(this.title));
		info.setContent(DianningUtil.filterKeyword(this.content));
		info.setAreaId(this.areaId);
		info.setTradingareaId(this.tid);
		info.setUid(this.userSession.getUid());
		info.setName(this.linkman);
		info.setTel(this.phone);
		info.setIsbiz(boolean2int(this.biz));
		info.setIsProfile(boolean2int(this.profile));
		info.setPhoto(this.photo);
		if(this.photo==null || this.photo.isEmpty()){
			info.setPhotonum(0);
		}else{
			info.setPhotonum(this.photo.size());
		}
		info.setAvatar("");
		info.setValidated(0);
		info.setStatus(1);
		info.setAddTime(new Date());
		info.setUpTime(new Date());
		info.setIsCityTop(0);
		info.setCityTopTime(new Date());
		info.setIsAreaTop(0);
		info.setAreaTopTime(new Date());
		info.setIsCommend(0);
		info.setCommendTime(new Date());
		
		List infoExpands = new ArrayList();
		//jiaoyouNanyouType
		Parameter pNanyouType = this.getParameterService().findParameterById(this.jiaoyouNanyouType);
		InfoExpand infoNanyouType = new InfoExpand();
		infoNanyouType.setKeyword("jiaoyouNanyouType");
		infoNanyouType.setSvalue(pNanyouType.getParamName());
		infoNanyouType.setIvalue(this.jiaoyouNanyouType);
		infoExpands.add(infoNanyouType);
		//jiaoyouXingbie
		Parameter pXingbie = this.getParameterService().findParameterById(this.xingbie);
		InfoExpand infoXingbie = new InfoExpand();
		infoXingbie.setKeyword("jiaoyouXingbie");
		infoXingbie.setSvalue(pXingbie.getParamName());
		infoXingbie.setIvalue(this.xingbie);
		infoExpands.add(infoXingbie);
		//jiaoyouAge
		Parameter pAge = this.getParameterService().findParameterById(this.jiaoyouAge);
		InfoExpand infoAge = new InfoExpand();
		infoAge.setKeyword("jiaoyouAge");
		infoAge.setSvalue(pAge.getParamName());
		infoAge.setIvalue(this.jiaoyouAge);
		infoExpands.add(infoAge);
		//jiaoyouNianling
		InfoExpand infoHangye = new InfoExpand();
		infoHangye.setKeyword("jiaoyouNianling");
		infoHangye.setSvalue(String.valueOf(this.nianling));
		infoHangye.setIvalue(this.nianling);
		infoExpands.add(infoHangye);
		//jiaoyouFangche
		Parameter pFangche = this.getParameterService().findParameterById(this.fangche);
		InfoExpand infoFangche = new InfoExpand();
		infoFangche.setKeyword("jiaoyouFangche");
		infoFangche.setSvalue(pFangche.getParamName());
		infoFangche.setIvalue(this.fangche);
		infoExpands.add(infoFangche);
		//jiaoyouShouru
		Parameter pShouru = this.getParameterService().findParameterById(this.shouru);
		InfoExpand infoShouru = new InfoExpand();
		infoShouru.setKeyword("jiaoyouShouru");
		infoShouru.setSvalue(pShouru.getParamName());
		infoShouru.setIvalue(this.shouru);
		infoExpands.add(infoShouru);
		//jiaoyouXuexing
		Parameter pXuexing = this.getParameterService().findParameterById(this.xuexing);
		InfoExpand infoXuexing = new InfoExpand();
		infoXuexing.setKeyword("jiaoyouXuexing");
		infoXuexing.setSvalue(pXuexing.getParamName());
		infoXuexing.setIvalue(this.xuexing);
		infoExpands.add(infoXuexing);
		//jiaoyouXingzuo
		Parameter pXingzuo = this.getParameterService().findParameterById(this.xingzuo);
		InfoExpand infoXingzuo = new InfoExpand();
		infoXingzuo.setKeyword("jiaoyouXingzuo");
		infoXingzuo.setSvalue(pXingzuo.getParamName());
		infoXingzuo.setIvalue(this.xingzuo);
		infoExpands.add(infoXingzuo);
		//jiaoyouHunyin
		Parameter pHunyin = this.getParameterService().findParameterById(this.hunyin);
		InfoExpand infoHunyin = new InfoExpand();
		infoHunyin.setKeyword("jiaoyouHunyin");
		infoHunyin.setSvalue(pHunyin.getParamName());
		infoHunyin.setIvalue(this.hunyin);
		infoExpands.add(infoHunyin);
		//jiaoyouShengao
		Parameter pShengao = this.getParameterService().findParameterById(this.shengao);
		InfoExpand infoShengao = new InfoExpand();
		infoShengao.setKeyword("jiaoyouShengao");
		infoShengao.setSvalue(pShengao.getParamName());
		infoShengao.setIvalue(this.shengao);
		infoExpands.add(infoShengao);
		//jiaoyouTizhong
		Parameter pTizhong = this.getParameterService().findParameterById(this.tizhong);
		InfoExpand infoTizhong = new InfoExpand();
		infoTizhong.setKeyword("jiaoyouTizhong");
		infoTizhong.setSvalue(pTizhong.getParamName());
		infoTizhong.setIvalue(this.tizhong);
		infoExpands.add(infoTizhong);
		//jiaoyouXueli
		Parameter pXueli = this.getParameterService().findParameterById(this.xueli);
		InfoExpand infoXueli = new InfoExpand();
		infoXueli.setKeyword("jiaoyouXueli");
		infoXueli.setSvalue(pXueli.getParamName());
		infoXueli.setIvalue(this.xueli);
		infoExpands.add(infoXueli);
		//jiaoyouZhiye
		Parameter pZhiye = this.getParameterService().findParameterById(this.zhiye);
		InfoExpand infoZhiye = new InfoExpand();
		infoZhiye.setKeyword("jiaoyouZhiye");
		infoZhiye.setSvalue(pZhiye.getParamName());
		infoZhiye.setIvalue(this.zhiye);
		infoExpands.add(infoZhiye);
		//jiaoyouAihao
		InfoExpand infoAihao = new InfoExpand();
		infoAihao.setKeyword("aihao");
		infoAihao.setSvalue(this.aihao);
		infoAihao.setIvalue(0);
		infoExpands.add(infoAihao);
		//jiaoyouQQ
		InfoExpand infoQQ = new InfoExpand();
		infoQQ.setKeyword("qq");
		infoQQ.setSvalue(this.qq);
		infoQQ.setIvalue(0);
		infoExpands.add(infoQQ);
		
		info = this.getInfoService().saveInfo(info, infoExpands);
		this.id = info.getId();
		return "dopost";
	}
	

	public String update(){
		
		this.setAction("doupdate");
		this.setInfo(this.getInfoService().findInfoById(this.id));
		if(this.getInfo() == null){
			return "infodisable";
		}else{
			if(this.getInfo().getValidated() == 2){
				return "infodisable";
			}
		}
		ChannelContact cc = this.getChannelService().findChannelContactById(this.sid);
		this.bid = cc.getParentId();
		this.sid = this.info.getCcid();
		this.areaId = this.info.getAreaId();
		this.tid = this.info.getTradingareaId();
		this.title = this.info.getTitle();
		this.content = this.info.getContent();
		this.linkman = this.info.getName();
		this.phone = this.info.getTel();
		this.biz = int2boolean(this.info.getIsbiz());
		this.profile = int2boolean(this.info.getIsProfile());
		this.photo = this.info.getPhoto();
		this.photonum = this.info.getPhotonum();
		
		//jiaoyouNanyouType
		InfoExpand infoNanyouType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouNanyouType");
		this.jiaoyouNanyouType = infoNanyouType.getIvalue();
		//jiaoyouXingbie
		InfoExpand jiaoyouXingbie = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouXingbie");
		this.xingbie = jiaoyouXingbie.getIvalue();
		//jiaoyouAge
		InfoExpand infoAge = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouAge");
		this.jiaoyouAge = infoAge.getIvalue();
		//jiaoyouNianling
		InfoExpand jiaoyouNianling = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouNianling");
		this.nianling = jiaoyouNianling.getIvalue();
		//jiaoyouFangche
		InfoExpand jiaoyouFangche = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouFangche");
		this.fangche = jiaoyouFangche.getIvalue();
		//jiaoyouShouru
		InfoExpand jiaoyouShouru = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouShouru");
		this.shouru = jiaoyouShouru.getIvalue();
		//jiaoyouXuexing
		InfoExpand jiaoyouXuexing = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouXuexing");
		this.xuexing = jiaoyouXuexing.getIvalue();
		//jiaoyouXingzuo
		InfoExpand jiaoyouXingzuo = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouXingzuo");
		this.xingzuo = jiaoyouXingzuo.getIvalue();
		//jiaoyouHunyin
		InfoExpand jiaoyouHunyin = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouHunyin");
		this.hunyin = jiaoyouHunyin.getIvalue();
		//jiaoyouShengao
		InfoExpand jiaoyouShengao = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouShengao");
		this.shengao = jiaoyouShengao.getIvalue();
		//jiaoyouTizhong
		InfoExpand jiaoyouTizhong = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouTizhong");
		this.tizhong = jiaoyouTizhong.getIvalue();
		//jiaoyouXueli
		InfoExpand jiaoyouXueli = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouXueli");
		this.xueli = jiaoyouXueli.getIvalue();
		//jiaoyouZhiye
		InfoExpand jiaoyouZhiye = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouZhiye");
		this.zhiye = jiaoyouZhiye.getIvalue();
		//Aihao
		InfoExpand jiaoyouAihao = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "aihao");
		this.aihao = jiaoyouAihao.getSvalue();
		//qq
		InfoExpand jiaoyouQQ = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "qq");
		this.qq = jiaoyouQQ.getSvalue();
		initValues();
		return "update";
	}
	
	public String doupdate(){
		ChannelContact cc = this.getChannelService().findChannelContactById(this.sid);
		Info info = this.getInfoService().findInfoById(this.id);
		info.setCid(cc.getChannelId());
		info.setCcid(this.sid);
		info.setTitle(DianningUtil.filterKeyword(this.title));
		info.setContent(DianningUtil.filterKeyword(this.content));
		info.setAreaId(this.areaId);
		info.setTradingareaId(this.tid);
		info.setUid(this.userSession.getUid());
		info.setName(this.linkman);
		info.setTel(this.phone);
		info.setIsbiz(boolean2int(this.biz));
		info.setIsProfile(boolean2int(this.profile));
		info.setPhoto(this.photo);
		if(this.photo==null || this.photo.isEmpty()){
			info.setPhotonum(0);
		}else{
			info.setPhotonum(this.photo.size());
		}
		
		List infoExpands = new ArrayList();
		//jiaoyouNanyouType
		Parameter pNanyouType = this.getParameterService().findParameterById(this.jiaoyouNanyouType);
		InfoExpand infoNanyouType = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouNanyouType");
		infoNanyouType.setSvalue(pNanyouType.getParamName());
		infoNanyouType.setIvalue(this.jiaoyouNanyouType);
		infoExpands.add(infoNanyouType);
		//jiaoyouXingbie
		Parameter pXingbie = this.getParameterService().findParameterById(this.xingbie);
		InfoExpand infoXingbie = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouXingbie");
		infoXingbie.setKeyword("jiaoyouXingbie");
		infoXingbie.setSvalue(pXingbie.getParamName());
		infoXingbie.setIvalue(this.xingbie);
		infoExpands.add(infoXingbie);
		//jiaoyouAge
		Parameter pAge = this.getParameterService().findParameterById(this.jiaoyouAge);
		InfoExpand infoAge = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouAge");
		infoAge.setSvalue(pAge.getParamName());
		infoAge.setIvalue(this.jiaoyouAge);
		infoExpands.add(infoAge);
		//jiaoyouNianling
		InfoExpand infoHangye = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouNianling");
		infoHangye.setKeyword("jiaoyouNianling");
		infoHangye.setSvalue(String.valueOf(this.nianling));
		infoHangye.setIvalue(this.nianling);
		infoExpands.add(infoHangye);
		//jiaoyouFangche
		Parameter pFangche = this.getParameterService().findParameterById(this.fangche);
		InfoExpand infoFangche = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouFangche");
		infoFangche.setKeyword("jiaoyouFangche");
		infoFangche.setSvalue(pFangche.getParamName());
		infoFangche.setIvalue(this.fangche);
		infoExpands.add(infoFangche);
		//jiaoyouShouru
		Parameter pShouru = this.getParameterService().findParameterById(this.shouru);
		InfoExpand infoShouru = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouShouru");
		infoShouru.setKeyword("jiaoyouShouru");
		infoShouru.setSvalue(pShouru.getParamName());
		infoShouru.setIvalue(this.shouru);
		infoExpands.add(infoShouru);
		//jiaoyouXuexing
		Parameter pXuexing = this.getParameterService().findParameterById(this.xuexing);
		InfoExpand infoXuexing = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouXuexing");
		infoXuexing.setKeyword("jiaoyouXuexing");
		infoXuexing.setSvalue(pXuexing.getParamName());
		infoXuexing.setIvalue(this.xuexing);
		infoExpands.add(infoXuexing);
		//jiaoyouXingzuo
		Parameter pXingzuo = this.getParameterService().findParameterById(this.xingzuo);
		InfoExpand infoXingzuo = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouXingzuo");
		infoXingzuo.setKeyword("jiaoyouXingzuo");
		infoXingzuo.setSvalue(pXingzuo.getParamName());
		infoXingzuo.setIvalue(this.xingzuo);
		infoExpands.add(infoXingzuo);
		//jiaoyouHunyin
		Parameter pHunyin = this.getParameterService().findParameterById(this.hunyin);
		InfoExpand infoHunyin = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouHunyin");
		infoHunyin.setKeyword("jiaoyouHunyin");
		infoHunyin.setSvalue(pHunyin.getParamName());
		infoHunyin.setIvalue(this.hunyin);
		infoExpands.add(infoHunyin);
		//jiaoyouShengao
		Parameter pShengao = this.getParameterService().findParameterById(this.shengao);
		InfoExpand infoShengao = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouShengao");
		infoShengao.setKeyword("jiaoyouShengao");
		infoShengao.setSvalue(pShengao.getParamName());
		infoShengao.setIvalue(this.shengao);
		infoExpands.add(infoShengao);
		//jiaoyouTizhong
		Parameter pTizhong = this.getParameterService().findParameterById(this.tizhong);
		InfoExpand infoTizhong = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouTizhong");
		infoTizhong.setKeyword("jiaoyouTizhong");
		infoTizhong.setSvalue(pTizhong.getParamName());
		infoTizhong.setIvalue(this.tizhong);
		infoExpands.add(infoTizhong);
		//jiaoyouXueli
		Parameter pXueli = this.getParameterService().findParameterById(this.xueli);
		InfoExpand infoXueli = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouXueli");
		infoXueli.setKeyword("jiaoyouXueli");
		infoXueli.setSvalue(pXueli.getParamName());
		infoXueli.setIvalue(this.xueli);
		infoExpands.add(infoXueli);
		//jiaoyouZhiye
		Parameter pZhiye = this.getParameterService().findParameterById(this.zhiye);
		InfoExpand infoZhiyei = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "jiaoyouZhiye");
		infoZhiyei.setKeyword("jiaoyouZhiye");
		infoZhiyei.setSvalue(pZhiye.getParamName());
		infoZhiyei.setIvalue(this.zhiye);
		infoExpands.add(infoZhiyei);
		//jiaoyouAihao
		InfoExpand infoAihao = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "aihao");
		infoAihao.setKeyword("aihao");
		infoAihao.setSvalue(this.aihao);
		infoAihao.setIvalue(0);
		infoExpands.add(infoAihao);
		//jiaoyouQQ
		InfoExpand infoQQ = this.getInfoService().findInfoExpandByInfoIdKeyword(this.id, "qq");
		infoQQ.setKeyword("qq");
		infoQQ.setSvalue(this.qq);
		infoQQ.setIvalue(0);
		infoExpands.add(infoQQ);

		info = this.getInfoService().updateInfo(info, infoExpands);
		return "doupdate";
	}







}
